/**
 * create by young (young2f@outlook.com) on 2020/9/16
 */


'use strict';
import React from 'react';
import {Button, DatePicker, Form, Input, InputNumber, notification, Popconfirm, Select, Switch, Table} from 'antd';

import {FormField, FormLayout, ModalFooter, ModalView, SearchForm} from 'antd-extra';
import FormBase from '../../../components/Base/FormBase';
import {connect} from "dva";
import moment from 'moment';
import 'moment/locale/zh-cn';

import ViewTitle from "../../../components/ViewTitle";
import EditableTable from '../../../components/EditableTable';

moment.locale('zh-cn');

@Form.create()
@connect(({
            tenant,
            global,
            dynamicLabel,
            dic
          }) => ({...tenant, ...dic, ...dynamicLabel, ...global}))
export default class ModalCreateOrEditDic2 extends FormBase {
  constructor(props) {
    super(props);
    this.state = {};
  }

  componentDidMount() {
    console.log('ModalCreateOrEdit2 componentDidMount');

  }

  renderFoot = () => {
    const {foot, value, record, callback, modalRef, form} = this.props;

    if (foot) {
      return foot(value, modalRef);
    } else {
      return (
        <ModalFooter>
          <Button type="primary" onClick={() => {
            form.validateFields((err, values) => {

              if (err) {
                const {code} = err;
                const {errors} = code;
                errors.forEach(item => {
                  notification.error(item);
                });
                return;
              }
              values._code = record ? record._code : new Date().valueOf();
              callback(values);
              modalRef.close();
            });

          }}>确定</Button>
          <Button onClick={() => {
            modalRef.close();
          }}>取消</Button>
        </ModalFooter>
      );
    }
  };

  render() {
    const {form, cols, record} = this.props;
    console.log('ModalCreateOrEdit2 render',cols,record);
    return (
      <div>
        <FormLayout form={form} cols={1}>
          {this.getDicFields(cols, record)}
        </FormLayout>
        {this.renderFoot()}
      </div>
    );
  }
}

